<?php
/*
 * @Author: ljj 635856627@qq.com
 * @Date: 2023-03-30 22:35:21
 * @LastEditors: ljj 635856627@qq.com
 * @LastEditTime: 2025-05-19 00:18:04
 * @FilePath: \web-single\app\single\api\DayOnline.php
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// +----------------------------------------------------------------------
// | title: 标题注释
// +----------------------------------------------------------------------
// | Author: TZ.Leong
// +----------------------------------------------------------------------
// | Date: 2019/7/15 11:23
// +----------------------------------------------------------------------

namespace app\single\api;


use app\single\model\DayOnlineModel;
use think\facade\Log;

class DayOnline
{
    public function run($params)
    {
        $data["ret"] = 1;
        $currentTimestamp = time();

        // 计算最近 5 分钟的整数倍时间戳
       $alignedTimestamp = $currentTimestamp - ($currentTimestamp % 300);
        $sDate = date("Ymd", strtotime($params["sDate"]));
        $eDate = date("Ymd", strtotime($params["sDate"]));
        $model = new DayOnlineModel();
        
        // $onlineData = $model->whereBetween("day", [$sDate, $eDate])->field("id", true)->select()->toArray();
        $onlineData = $model->whereBetween("day",[$sDate,$eDate])->field("id",true)->select()->toArray();
        $newlist = [];
        foreach($onlineData as $row){
            $row["master_platform"]= PLATFORM;
            $newlist[] =$row;
        }
        $data["data"] = $newlist;
//         $newOnlineData =[];
//         //在这里统一返回前五分钟的数据 去掉当前最新
//         if ($sDate == date("Ymd")) {
//             foreach ($onlineData as  $row) {
                
//             //    $lastKey = date('H:i', $alignedTimestamp);
//                 // $v = $row["online_txt"]  ?? [];
//                 // if(!empty($v)) {
//                     // $onlinetxt = unserialize($v);
//                 //    unset($onlinetxt[$lastKey]);
//                     // $row["online_txt"] = serialize($onlinetxt);
//                 // }
//                 $newOnlineData[] = $row;
//             }
//         }
// //        Log::info("debug DayOnline". json_encode($newOnlineData));
//         $data["data"] = $newOnlineData;
        return $data;
    }
}